<script setup lang="ts">
import GoodsItem from '@/views/category/components/goods-item.vue'
import { PropType } from 'vue'
import useStore from '@/store'
import { useRoute } from 'vue-router'
import { apiLazy } from '@/utils/hooks'
const props = defineProps({
  type: {
    type: Number as PropType<1 | 2 | 3>,
    default: 1
  }
})

// 标题对象
const titleObj = {
  1: '24小时热销榜',
  2: '周热销榜',
  3: '总热销榜'
}
//
const { goods } = useStore()
const route = useRoute()
const target = apiLazy(() => {
  goods.getGoodsHotList(route.params.id as string, props.type)
})
</script>

<template>
  <div class="goods-hot" ref="target">
    <h3>{{ titleObj[props.type] }}</h3>
    <div class="goods-list">
      <!-- 商品区块 -->
      <GoodsItem
        :goods="item"
        v-for="(item, index) in goods.goodsHotList[type - 1]"
        :key="index"
      />
    </div>
  </div>
</template>

<style scoped lang="less">
.goods-hot {
  background-color: #fff;
  margin-bottom: 20px;
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-list {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 200px;
  }
}
</style>
